package com.itheima.mapper;

import com.itheima.pojo.Employee;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
//交给IOC管理
@Repository
public interface EmployeeMapper {

    //登陆方法----根据用户名和密码查询是否存在以及是否正确
    Employee selectByUsernameAnePassword(@Param("username") String username, @Param("password") String password);


    //更新token
    void updatetoken(@Param("token") String token, @Param("id") String id);


    //通过token查询
/*    Employee getByToken(String token);*/


    //清除token
/*
    @Update("update employee set token = null where id = #{id}")
    void clearToken(String id);
*/


    //根据Id查询
    @Select("select * from employee where id = #{id}")
    Employee getById(String id);

    //分页查询
    List<Employee> page(@Param("name") String name , @Param("start") Integer start , @Param("pageSize") Integer pageSize);

    //计算 total(总条数)(通过名字)
    long countEmplyee(@Param("name") String name);


    //新增员工
    @Insert("insert into employee (id,`name`,username,password,phone,sex,id_number,status) values (#{id},#{name},#{username},#{password},#{phone},#{sex},#{idNumber},#{status})")
    int addEmployee(Employee employee);

    //修改员工
    int updateEmployee(Employee employee);
}
